package com.mys2sh.dao.impl;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import com.mys2sh.dao.UserDao;
import com.mys2sh.model.User;

public class UserDaoImpl extends SqlMapClientDaoSupport implements UserDao {

	public User getUserInfoByUid(int uid) {
		return (User) getSqlMapClientTemplate().queryForObject(
				"getUserInfoByUid", uid);
	}

	public User getUserInfoByUserName(String userName) {
		return (User) getSqlMapClientTemplate().queryForObject(
				"getUserInfoByUserName", userName);
	}

	public void setUserInfo(User user) {

		SimpleDateFormat ft = null;
		Date date = null;
		Calendar cl = Calendar.getInstance();
		cl.setTime(new java.util.Date());
		date = cl.getTime();

		ft = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String dateTime = ft.format(date);

		user.setUpdateDate(dateTime);
		user.setCreateDate(dateTime);

		getSqlMapClientTemplate().insert("setUserInfo", user);
	}

}
